﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Commands;

namespace ModuleA.ViewModels
{
    public class PersonListViewModel:BindableBase
    {
        private IRegionManager _regionManager;
        public DelegateCommand<Person> PersonSelectedCmd { get; private set; }
        public DelegateCommand<object> DeletePersonViewCmd { get; private set; }
        public DelegateCommand TestCmd { get; set; }
        private ObservableCollection<Person> _people;
        public ObservableCollection<Person> People
        {
            get => _people;
            set => SetProperty(ref _people, value);
        }
        private string _testMes;
        public string TestMes
        {
            get => _testMes;
            set => SetProperty(ref _testMes, value);
        }

        public PersonListViewModel(IRegionManager regionManager)
        {
            TestMes = "77632";
            _regionManager = regionManager;
            People = new ObservableCollection<Person>();
            for (int i = 0; i < 100; i++)
            {
                People.Add(new Person() { FirstName = "FirstName" + i, LastName = "LastName" + i, Age = i });
            }
            PersonSelectedCmd = new DelegateCommand<Person>(person =>
              {
                  var parameters = new NavigationParameters();
                  parameters.Add("person", person);
                  if (person != null)
                      _regionManager.RequestNavigate("PersonDetailsRegion", "PersonDetail", parameters);
              });
            DeletePersonViewCmd = new DelegateCommand<object>(view =>
              {
                  _regionManager.Regions["PersonDetailsRegion"].Remove(view);
              });
            TestCmd = new DelegateCommand(() =>
              {

              });
        }
    }
}
